<?php

/**
 * 
 * IndexAction.class.php(后台首页)
 *
 * @package      	YOURPHP
 * @author          liuxun QQ:147613338 <admin@yourphp.cn>
 * @copyright     	Copyright (c) 2008-2011  (http://www.yourphp.cn)
 * @license         http://www.yourphp.cn/license.txt
 * @version        	YourPHP企业网站管理系统 v2.1 2012-10-08 yourphp.cn $
 */
if(!defined("Yourphp")) exit("Access Denied");
class RecruitAction extends AdminbaseAction
{
    protected   $title;
    function _initialize()
    {
		parent::_initialize();
                $this->title = array('')  ;

    }

    public function index() {
        import('@.ORG.Page');
        $keyword = $_GET['zhuanye'];
        $where = array();
        if (!empty($keyword)) {
            $where['zhuanye'] = array('like', '%' . $keyword . '%');
        }
        $count = M('recruit')->where($where)->count();
        $page = new Page($count, 20);
        $show = $page->show();
        $this->assign("page", $show);
        $zhuanye = M('zhuanye')->field('id,title')->select();
        $list = M('recruit')->order('id desc')->where($where)->limit($page->firstRow . ',' . $page->listRows)->select();
        $this->assign('list', $list);
        $this->assign('zhuanye', $zhuanye);
        $this->assign('keyword', $keyword);
        $this->display();
    }

    //导入
    public function daoru() {
        $url = $this->_uploads($_FILES['excel']);
        $data = $this->import_excel($url['name']);
        foreach ($data as $key => $value) {
            if (!empty($value)) {
                $order['zhuanye'] = $_POST['zhuanye'];
                $order['title'] = $value[1];
                $order['companyname'] = $value[2];
                $order['salary'] = $value[3];
                $order['workplace'] = $value[4];
                $order['comefrom'] = $value[5];
                $order['url'] = $value[6];
                $order['createtime'] = time();
                $abc = M('recruit')->add($order);
            }
        }
        if ($abc) {
            $this->success('导入成功');
        }
    }

    function import_excel($file) {
        // 判断文件是什么格式
        $type = substr(strrchr($file, '.'), 1);
        ini_set('max_execution_time', '0');
        import("@.ORG.PHPExcel");
        if($type == 'xlsx'){
            $objReader =\PHPExcel_IOFactory::createReader('Excel2007');
            $objPHPExcel =$objReader->load($file, $encode = 'utf-8');
        } 
        elseif($type == 'xls' ){
            $objReader =\PHPExcel_IOFactory::createReader('Excel5');
            $objPHPExcel =$objReader->load($file, $encode = 'utf-8');
        }

        $sheet = $objPHPExcel->getSheet(0);
        // 取得总行数
        $highestRow = $sheet->getHighestRow();
        // 取得总列数
        $highestColumn = $sheet->getHighestColumn();
        //循环读取excel文件,读取一条,插入一条
        $data = array();
        //从第一行开始读取数据
        for ($j = 2; $j <= $highestRow; $j++) {
            //从A列读取数据
            for ($k = 'A'; $k <= $highestColumn; $k++) {
                // 读取单元格
                $data[$j][] = $objPHPExcel->getActiveSheet()->getCell("$k$j")->getValue();
            }
        }
        return $data;
    }
    
    
    

}
?>